package cn.dapeng.features;

import java.util.concurrent.Exchanger;

public class Exchanger_T01 {

    static Exchanger<String> exchanger = new Exchanger<>();

    public static void main(String[] args) {
        new Thread(() -> {
            String s = "T1";
            try {
                s = exchanger.exchange(s);
            } catch (InterruptedException e) {

            }
            System.out.println(Thread.currentThread().getName() + ":" + s);
        }, "t1").start();

        new Thread(() -> {
            String s = "T2";
            try {
                s = exchanger.exchange(s);
            } catch (InterruptedException e) {

            }
            System.out.println(Thread.currentThread().getName() + ":" + s);
        }, "t2").start();

//        new Thread(() -> {
//            String s = "T3";
//            try {
//                s = exchanger.exchange(s);
//            } catch (InterruptedException e) {
//
//            }
//            System.out.println(Thread.currentThread().getName() + ":" + s);
//        }, "t3").start();
    }
}
